package org.example.subside.List;


import org.example.subside.List.pojo.User;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class MultiFilterTest {
    public static void main(String[] args) {
        List<User> userList = getUserList();
 
        // 筛选 age > 18 && address = "上海" 的user
        List<User> filterList = userList.stream().filter(user -> filterAgeAndAddress(user,18,"上海")).collect(Collectors.toList());
 
        filterList.forEach(System.out::println);
    }
 
    // 筛选 age > 18 && address = "上海" 的user
    private static boolean filterAgeAndAddress(User user,Integer age,String address){
        if(user.getAge() > 18 && address.equals(user.getAddress())){
            return true;
        }
        return false;
    }
 
    private static List<User> getUserList() {
        List<User> userList = new ArrayList<>();
        userList.add(new User(1,"张三",18,"上海"));
        userList.add(new User(2,"王五",16,"上海"));
        userList.add(new User(3,"李四",20,"上海"));
        userList.add(new User(4,"张雷",22,"北京"));
        userList.add(new User(5,"张超",15,"深圳"));
        userList.add(new User(6,"李雷",24,"北京"));
        userList.add(new User(7,"王爷",21,"上海"));
        userList.add(new User(8,"张三丰",18,"广州"));
        userList.add(new User(9,"赵六",16,"广州"));
        userList.add(new User(10,"赵无极",26,"深圳"));
        return userList;
    }
}